<?php

namespace App\Http\Controllers\Api\Members;

use App\Http\Controllers\Controller;
use App\Libs\Strategy\Context;
use App\Models\Members;
use Illuminate\Http\Request;

class MembersController extends Controller
{
    private $member;

    public function __construct()
    {
        $this->member = new Context(new Members());
    }

    public function index(Request $request)
    {
        $members = $this->member->display(request()->limit,function($query) use ($request){
            if($request->keyword)
            {
                $query->where('nickname','like','%'.$request->keyword.'%')->orWhere('mobile',$request->keyword);
            }
            if($request->referee_phone)
            {
                $query->where('referee_phone','like','%'.$request->referee_phone.'%');
            }
        });
        return $this->success($members);
    }

    // 我的团队
    public function show($id){
        $children = $this->member->display(request()->limit,function($query) use ($id){
            $query->where('pid',$id);
        });
        return $this->success($children);
    }
}
